<template>
  <el-dialog
    title="角色分配"
    width="500px"
    :visible="isShow"
    @close="closeEvent"
  >
    <el-checkbox-group v-model="value">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{
        item.name
      }}</el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <div style="text-align: center">
        <el-button type="primary" @click="submit">确定</el-button>
        <el-button @click="closeEvent">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import { sysRole } from '@/api/setting.js'
import { sysUser } from '@/api/user.js'
import { sysUserAssignRloes } from '@/api/employees'
export default {
  props: {
    isShow: { type: Boolean, default: false }
  },
  data() {
    return {
      value: [],
      list: [],
      id: ''
    }
  },
  created() {
    this.getData()
  },
  methods: {
    closeEvent() {
      this.$emit('update:isShow', false)
      this.value = []
    },
    async getData() {
      const res = await sysRole({ page: 1, pageszie: 1000 })
      this.list = res.data.rows
    },
    // 获取当前账号的详情信息包括角色信息
    async getUserInfo(id) {
      this.id = id
      const res = await sysUser(id)
      this.value = res.data.roleIds
    },
    async submit() {
      await sysUserAssignRloes(this.id, this.value)
      this.closeEvent()
    }
  }
}
</script>

<style></style>
